﻿CREATE PROCEDURE dbo.TPW_SERVICE_RECENT_WK_LOG
	@inLast_Time	DATETIME
AS
	SELECT
		L.LOG_TIME,
		L.REFER_ID,
		O.STATE_NAME				AS OLD_STATE,
		E.EVENT_NAME				AS EVENT_,
		N.STATE_NAME				AS NEW_STATE,
		L.MESSAGE_
	FROM
		dbo.TPW_WK_LOG						L
		INNER JOIN dbo.TPW_WF_STATE			N
		ON (N.STATE_ID	= L.STATE_ID_NEW)
		LEFT JOIN dbo.TPW_WF_STATE			O
		ON (O.STATE_ID	= L.STATE_ID_OLD)
		LEFT JOIN dbo.TPW_WF_EVENT			E
		ON (E.EVENT_ID	= L.EVENT_ID)
	WHERE
		L.LOG_TIME		> @inLast_Time
	ORDER BY
		L.LOG_TIME,
		L.REFER_ID;
